const app = getApp()
Page({
  data: {
    code:'',
    codedata:{},
    loadingHidden:false,
    wordmax: 1000,
    text:'',
    current:0,
    show:"hide",
    name:''
  },
  onLoad: function (options) {
    var code = options.code;
    var that=this;
    that.setData({ code: code });
    that.gecodedata(code);
  },
  
  //限制300字数
  limit: function (event) {
    var value = event.detail.value;
    var length = parseInt(value.length);
    if (length > this.data.wordmax) {
      return;
    }
    this.setData({
      current: length,
      text: value
    });
  },
  //提交文字
  textSubmit: function (e) {
    var that = this;
    var text = that.data.text;
    var code = that.data.code;
    that.submittext(text,code);
  },
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  },

  //提交数据
  submittext: function (options,code) {
    var that = this;
    var text = options;
    var openid = app.globalData.openid;
    var link = app.globalData.schlink;
    var sign = app.globalData.bindInfo.sign;
    var uid = app.globalData.bindInfo.user_id;
    // if (text == "" || text == null || text==undefined){
    //   return;
    // }
    wx.request({
      url: getApp().globalData.baseUrl + 'savecodedata',
      data: {
        link: link,
        openid: openid,
        sign: sign,
        code: code,
        detail: text,
        uid: uid
      },
      method: "POST",
      header: {},
      success: function (res) {
        if(res.data.data.code==1){
          wx.showToast({
            title: res.data.data.msg,
            icon: 'succes',
            duration: 1500,
            mask: true
          })
         
        }else{
          wx.showToast({
            title: res.data.data.msg,
            icon: 'none',
            duration: 1500
          })
        }
        setTimeout(function () {
          wx.switchTab({
            url: '/pages/index/index',
          });
        }, 2000) 
       
      }
    })
  },
 
  
  //获取二维码数据
  gecodedata: function (options) {
    var that=this;
    var code = options;
    var openid = app.globalData.openid;
    var link = app.globalData.schlink;
    var sign = app.globalData.bindInfo.sign;
    // var code = "wW8Me7";
    var name="";
    wx.request({
      url: getApp().globalData.baseUrl + 'getcodedata',
      data: {
        link: link,
        openid: openid,
        sign: sign,
        code: code
      },
      method: "get",
      header: {},
      success: function (res) {
        if(res.data.data.code==1){
          that.setData({ codedata: res.data.data.data });
          that.setData({ show: "show" });
        }else{
          wx.showToast({
            title:res.data.data.msg,
            icon: 'none',
            duration: 1500
          })
          setTimeout(function () {
            wx.switchTab({
              url: '/pages/index/index',
            });
          }, 2000) 
        }
        that.setData({ loadingHidden: true });
       
      }
    })
  },
})